package com.ybdz.scanner.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ybdz.scanner.R;
import com.ybdz.scanner.base.BaseAdapter;
import com.ybdz.scanner.bean.ChuKuDanBean;
import com.ybdz.scanner.utils.UIUtils;

import java.util.List;

/**
 * Created by gs on 2018/3/21.
 */

public class chuKuDanAdapter extends BaseAdapter<chuKuDanAdapter.chuKuDanViewHolder>{

    private final LayoutInflater inflater;
    private List<ChuKuDanBean.DataBean.OutBatchBean> list ;

    public chuKuDanAdapter(Context context, List<ChuKuDanBean.DataBean.OutBatchBean> list) {
        inflater = LayoutInflater.from(context);
        this.list = list;
    }

    @Override
    public chuKuDanAdapter.chuKuDanViewHolder CreateChildViewHolder(ViewGroup parent, int viewType) {
        View view = this.inflater.inflate(R.layout.item_recycleview, parent, false);

        return new chuKuDanViewHolder(view);
    }

    public void setData(List<ChuKuDanBean.DataBean.OutBatchBean> data) {
        this.list = data;
    }

    @Override
    public void bindViewHolder(chuKuDanViewHolder holder, int position) {
        Integer quantity = list.get(position).getQuantity();
        String scanQuantity = String.valueOf(list.get(position).getScanQuantity());
        if (scanQuantity.equalsIgnoreCase("null")){
            scanQuantity = "0";
        }
        Integer anInt =  Integer.parseInt(scanQuantity);
        if (anInt <= 0){
            anInt = 0;
        }

        if (quantity == anInt){
            holder.mTvWeight.setTextColor(UIUtils.getColor(R.color.gray));
            holder.mTvName.setTextColor(UIUtils.getColor(R.color.gray));
            holder.mTvConformity.setTextColor(UIUtils.getColor(R.color.gray));
        }
        holder.mTvWeight.setText(list.get(position).getProductBatch());
        holder.mTvName.setText(list.get(position).getContractNumber());
        holder.mTvConformity.setText(list.get(position).getQuantity()+"");
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    class chuKuDanViewHolder extends BaseAdapter.BaseViewHolder{
        private final TextView mTvName;
        private final TextView mTvWeight;
        private final TextView mTvConformity;

        chuKuDanViewHolder(View view) {
            super(view);
            mTvName = (TextView) view.findViewById(R.id.tv_name);
            mTvWeight = (TextView) view.findViewById(R.id.tv_weight);
            mTvConformity = (TextView) view.findViewById(R.id.tv_conformity);
        }
    }
}
